<?php

require __DIR__."/../vendor/autoload.php";

ActiveRecord\Config::initialize(function($DbConfig)  {
    $DbConfig->set_model_directory('../Core/Models');
    $DbConfig->set_connections([
        'development' =>'mysql://wanzengchuang:wanzengchuang@rds2tzv3pi4963cf46zh.mysql.rds.aliyuncs.com/wanzengchuang'
    ]);
});

\lactone\Core\Models\SpiderModel::find(1);;

exit;

/*$Queue = new \lactone\Core\Queue\Queue([
    'Driver'        =>'file',
    'DriverArgs'    =>[
        'file'      =>__DIR__.'/Data/a'
    ]
]);

exit;*/
/*function swoole_timer_after(){

}*/
/*Lactone::setConfigs([
    'db' =>[
        'connect'=>[
            'development' =>'mysql://root:@192.168.1.109/lactone'
        ]
    ],
]);
$Spider = new \lactone\Core\Spider\Spiders();

$Spider->stepCutTaskFormTaskId(1520);
exit;


set_error_handler(array('Lactone','error_handle'));*/


$Config = require __DIR__."/Config/Config.php";


exit;


$Config['TaskQueue'] = [
    'Driver' =>'File'
];
$Config['taskCompleteQueue'] = [
    'Driver' =>'File'
];


Lactone::setConfigs($Config);

Lactone::initSpider();
Lactone::initLog();
//
$Data = [];

$Site = new \Spider\Site\zhihu_com([
    'task'=>[
        'id'    =>0,
        'url'       =>'http://www.zhihu.com/node/ProfileFollowersListV2',
        'request'   => [
            'method'    =>'ajaxpost',
            'Referer'   => 'http://www.zhihu.com/people/ringzero/followers',
            'params'    =>[
                'method' => 'next',
                'params' =>json_encode(['offset'=> 20,'order_by'=>'created','hash_id'=> 'aa15a1808f0b3a526df99769e03a2f84']),
                '_xsrf' =>'a3e7e654beeeadb20d49f47bd83720d0'
            ]
        ],
    ],
    'CookieDir' =>__DIR__.'/',
    'QueueArgs' =>[
        'file'          =>  __DIR__.'/asdasd_asdasd',
        'max_number'    => 10000
    ],
    'pdo' =>[
        'dsn'       =>'mysql:host=192.168.1.109;dbname=lactone',
        'username'  =>'root',
        'password'  =>'',
        'options'   =>[
            PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
        ]
    ]
]);



if(!$Site->send()){
    //任务执行失败
}else{
    //任务执行成功
}
exit;
